package SegmentTree._731_MyCalendarII;

import java.util.*;

public class MyCalendarTwo {
    TreeMap<Integer,Integer> calendars;
    public MyCalendarTwo() {
        this.calendars = new TreeMap<>();
    }
    //add note
    public boolean book(int start, int end) {
        calendars.put(start, calendars.getOrDefault(start, 0) + 1);
        calendars.put(end, calendars.getOrDefault(end, 0) - 1);
        int count = 0;
        for (int c : calendars.values()) {
            count += c;
            if (count >= 3) {
                calendars.put(start, calendars.get(start) - 1);
                calendars.put(end, calendars.get(end) + 1);
                return false;
            }
        }
        return true;
    }
}
